package com.ade.warehouse.config;

import com.ade.warehouse.page.AdminFilter;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import util.MockRedis;

import javax.servlet.DispatcherType;

@Configuration //这个注解说明这个类是个配置文件类，相当于XML了
//@PropertySource("classpath:jdbc.properties")//这个注解的含义是用来解析指定文件
public class JavaBean {

    @Bean(name = "loginMockRedis")
    public MockRedis mockRedis(){
        return new MockRedis();
    }

    @Bean
    public FilterRegistrationBean sessionFilter() {
        //新建过滤器注册类
        FilterRegistrationBean registration = new FilterRegistrationBean();
        // 添加我们写好的过滤器
        registration.setFilter( new AdminFilter());
        // 设置过滤器的URL模式
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        //匹配路径
        //List<String> urlPatterns = new ArrayList<>();
        //urlPatterns.add("/*");
        //registration.setUrlPatterns(urlPatterns);
        registration.addUrlPatterns("/*");
        //不过滤的路径，俗称白名单
        registration.addInitParameter("exclusions",
                "/views/direction.html,/views/login.html,/views/register.html" +
                        ",/user/login");

        //设置过滤器顺序
        registration.setOrder(1);
        return registration;
    }
}
